/**
 * Choicesoft.com.cn Inc.
 * Copyright (c) 2004-2019 All Rights Reserved.
 */
package com.choice.bill.calculate2.controller;

import com.choice.bill.calculate.client.CardClient;
import com.choice.bill.calculate.client.CouponClient;
import com.choice.bill.calculate.client.MemberClient;
import com.choice.bill.calculate.dto.crm.CardRequest;
import com.choice.bill.calculate.dto.crm.CardResponse;
import com.choice.bill.calculate.dto.crm.CouponRequest;
import com.choice.bill.calculate.dto.crm.CouponResponse;
import com.choice.bill.calculate.dto.crm.MemberRequest;
import com.choice.bill.calculate.dto.crm.MemberResponse;
import com.choice.bill.calculate.web.Result;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenxubing
 * @version : MemberController.java, v 0.1 2019-07-02 13:55 chenxubing Exp $$
 */
@Slf4j
@RestController
@RequestMapping(value = "/member")
public class MemberController {
    @Autowired
    private MemberClient memberClient;

    @Autowired
    private CardClient cardClient;

    @Autowired
    private CouponClient couponClient;

    @GetMapping("/query")
    @HystrixCommand(fallbackMethod = "queryFallback")
    public Result queryMember() {
        MemberRequest req = new MemberRequest();
        req.setMemberType(1);
        req.setTenantId("5b34965396d1900001878a9e");
        MemberResponse member = memberClient.query(req);
        Result res = Result.success(member);
        return res;
    }

    @GetMapping("/queryCard")
    @HystrixCommand(fallbackMethod = "queryFallback")
    public Result queryCard() {
        CardRequest req = new CardRequest();
        req.setMemberType(1);
        req.setTenantId("5b34965396d1900001878a9e");
        req.setStoreId("xxxx");
        req.setCardNo("6201000009871234");
        CardResponse card = cardClient.query(req);
        Result res = Result.success(card);
        return res;
    }

    @GetMapping("/queryCoupon")
    @HystrixCommand(fallbackMethod = "queryFallback")
    public Result queryCoupon() {
        CouponRequest req = new CouponRequest();
        req.setMemberType(1);
        req.setTenantId("5b34965396d1900001878a9e");
        List<CouponResponse> response = couponClient.query(req);
        Result res = Result.success(response);
        return res;
    }


    public Result queryFallback() {
        return Result.fail("超时");
    }
}
